#pragma once
#include "netLib/netExport.h"
#include <functional>
#include <string>
#include <vector>

struct bufferevent;

class API_EXPORT NetClient
{
public:
    typedef std::function<void(char*,int)> RecvFun;
    
public:
    NetClient();
    bool init(const std::string &ip,const int nPort);
    void send(const char *,int nSize);
    void loop();
    void disconnect();
    void setRecvCb(RecvFun *);
	
private:
    void recvCb(struct bufferevent *bufevt, void *ctx);
    friend void readCb(struct bufferevent *bufevt, void *ctx);
    
private:
    struct event_base* m_pBase;
    struct bufferevent* m_pConn = nullptr;
    RecvFun *m_recvFun = nullptr;
	std::vector<char> m_recvBuf;
    static NetClient *pNetClient;
};